package com.test.daily.leetcode.y2021.m12.day1221;

/**
 * @author Tom on 2021/12/21
 */
public class Code01_DayOfYear {
    public static void main(String[] args) {
        String date = "2012-01-02";
        Code01_DayOfYear cd = new Code01_DayOfYear();
        System.out.println(cd.dayOfYear(date));
    }
    public int dayOfYear(String date) {
        // date = "2019-01-09";
        String[] yearMonthDay = date.split("-");
        String year = yearMonthDay[0];
        String month = yearMonthDay[1];
        String day = yearMonthDay[2];
        int dayOfYear = 0;
        dayOfYear += Integer.parseInt(day);
        switch(month){
            case "01" : dayOfYear += 0; break;
            case "02" : dayOfYear += 31; break;
            case "03" : dayOfYear += 59; break;
            case "04" : dayOfYear += 90; break;
            case "05" : dayOfYear += 120; break;
            case "06" : dayOfYear += 151; break;
            case "07" : dayOfYear += 181; break;
            case "08" : dayOfYear += 212; break;
            case "09" : dayOfYear += 243; break;
            case "10" : dayOfYear += 273; break;
            case "11" : dayOfYear += 304; break;
            case "12" : dayOfYear += 334; break;
        }

        dayOfYear += (!(month.startsWith("01")||month.startsWith("02")))&&(Integer.valueOf(year)%400 == 0
                   || Integer.valueOf(year)%4 ==0 && Integer.valueOf(year)%100 != 0)? 1:0;
        return dayOfYear;
    }
}
